//
//  JKRFeedDetailLayout.m
//  JKRFeedDemo
//
//  Created by Lucky on 2017/12/10.
//  Copyright © 2017年 Lucky. All rights reserved.
//

#import "JKRFeedDetailLayout.h"

@implementation JKRFeedDetailLayout

- (instancetype)initWithModel:(JKRFeedDataModel *)model {
    self = [super init];
    self.model = model;
    [self _layout];
    return self;
}

- (void)_layout {
    [self _layoutProgress];
    [self _layoutStatus];
    [self _layoutTop];
    [self _layoutAuthor];
    [self _layoutBottom];
    [self _layoutContent];
    
    self.topHeight = CGRectGetMaxY(self.contentLayout.contentFrame) + 10;
}

- (void)_layoutProgress {
    self.progressLayout = [[JKRFeedProgressLayout alloc] initWithModel:self.model];
    self.progressLayout.progressFrame = CGRectMake(0, 0, kScreenWidth, 66);
}

- (void)_layoutStatus {
    self.statusLayout = [[JKRFeedStatusLayout alloc] initWithModel:self.model];
    if (self.progressLayout.show) {
        self.statusLayout.stautsFrame = CGRectMake(0, CGRectGetMaxY(self.progressLayout.progressFrame), kScreenWidth, 64);
    } else {
        self.statusLayout.stautsFrame = CGRectMake(0, 10, kScreenWidth, 64);
    }
}

- (void)_layoutTop {
    self.topLayout = [[JKRFeedTopLayout alloc] initWithModel:self.model];
    if (self.statusLayout.show) {
        self.topLayout.topFrame = CGRectMake(0, CGRectGetMaxY(self.statusLayout.stautsFrame) + 10, kScreenWidth, 139);
    } else {
        if (self.progressLayout.show) {
            self.topLayout.topFrame = CGRectMake(0, CGRectGetMaxY(self.progressLayout.progressFrame) + 10, kScreenWidth, 139);
        } else {
            self.topLayout.topFrame = CGRectMake(0, 10, kScreenWidth, 139);
        }
    }
}

- (void)_layoutAuthor {
    self.authorLayout = [[JKRFeedAuthorLayout alloc] initWithModel:self.model];
    if (self.topLayout.show) {
        self.authorLayout.authorFrame = CGRectMake(0, CGRectGetMaxY(self.topLayout.topFrame) + 10, kScreenWidth, 70);
    } else {
        if (self.statusLayout.show) {
            self.authorLayout.authorFrame = CGRectMake(0, CGRectGetMaxY(self.statusLayout.stautsFrame) + 10, kScreenWidth, 70);
        } else {
            if (self.progressLayout.show) {
                self.authorLayout.authorFrame = CGRectMake(0, CGRectGetMaxY(self.progressLayout.progressFrame) + 10, kScreenWidth, 70);
            } else {
                self.authorLayout.authorFrame = CGRectMake(0, 10, kScreenWidth, 70);
            }
        }
    }
}

- (void)_layoutBottom {
    self.bottomLayout = [[JKRFeedBottomLayout alloc] initWithModel:self.model];
    self.bottomLayout.bottomFrame = CGRectMake(0, CGRectGetMaxY(self.authorLayout.authorFrame), self.bottomLayout.bottomFrame.size.width, self.bottomLayout.bottomFrame.size.height);
}

- (void)_layoutContent {
    self.contentLayout = [[JKRFeedContentLayout alloc] initWithModel:self.model];
    if (self.bottomLayout.show) {
        self.contentLayout.contentFrame = CGRectMake(0, CGRectGetMaxY(self.bottomLayout.bottomFrame), self.contentLayout.contentFrame.size.width, self.contentLayout.contentFrame.size.height);
    } else {
        self.contentLayout.contentFrame = CGRectMake(0, CGRectGetMaxY(self.authorLayout.authorFrame), self.contentLayout.contentFrame.size.width, self.contentLayout.contentFrame.size.height);
    }
}

@end
